home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / ci-strcm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  444 b   |  30 lines

  1.  
  2. /* like strcmp, but case-insensitive */
  3.  
  4. #include <ctype.h>
  5.  
  6. static char char_upcase(ch)
  7. char ch;
  8. {
  9.   if (islower(ch))
  10.     return(toupper(ch));
  11.     else
  12.     return(ch);
  13. }
  14.  
  15. int
  16. ci_strcmp(s1, s2)
  17. char    * s1;
  18. char    * s2;
  19. {
  20.   char ch1, ch2;
  21.  
  22.   if (!s1 && s2) return(-1);
  23.   if (!s2 && s1) return(1);
  24.   if (!s1 && !s2) return(0);
  25.   while (char_upcase(*s1) == char_upcase(*s2++))
  26.     if (!*s1++)
  27.         return 0;
  28.   return *s1 - *--s2;
  29. }
  30.